package	com.sdry.web.controller.jyy.plan;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sdry.model.jyy.plan.PlanDetail;
import com.sdry.service.jyy.plan.PlanDetailService;
import com.sdry.utils.DateJsonValueProcessor;
import com.sdry.utils.ResponseUtil;
/**
 *
 *@ClassName: PlanDetailController
 *@Description: 
 *@Author jyy
 *@Date 2019-09-28 16:08:36
 *@version 1.0
*/
@Controller
@RequestMapping("/planDetail")
public class PlanDetailController{
	@Resource PlanDetailService PlanDetailService;

	/** 
	 * 根据主键id查询实体
	 * @param id 主键id
	 * @return 实体
	*/
	@RequestMapping("/queryById")
	@ResponseBody
	public PlanDetail queryById(Long id) {
		PlanDetail param = PlanDetailService.queryById(id);
		return param;
	}
	/** 
	 * 条件查询所有
	 * @param param 实体条件
	 * @return 实体集合
	*/
	@RequestMapping("/queryAllByMution")
	@ResponseBody
	public List<PlanDetail> queryAllByMution(PlanDetail param) {
		List<PlanDetail> list = PlanDetailService.queryAllByMution(param);
		return list;
	}
	/** 
	 * 条件分页查询
	 * @param param 实体条件
	 * @param response
	 * @throws Exception
	*/
	@RequestMapping("/list")
	public void list(PlanDetail param,HttpServletResponse response) throws Exception{
		/*
		 * 条件分页查询内容
		 */
		List<PlanDetail> list = PlanDetailService.findPageByMution(param);
		/*
		 * 条件查询总条数
		 */
		Integer total = PlanDetailService.selectCountByMution(param);
		/*
		 * 转为json数据传至页面
		 */
		JsonConfig jsonConfig = new JsonConfig();
		jsonConfig.registerJsonValueProcessor(Date.class, new DateJsonValueProcessor("yyyy-MM-dd HH:mm:ss"));
		//创建result
		JSONObject result = new JSONObject();
		//转json数据
		JSONArray jsonArray = JSONArray.fromObject(list, jsonConfig);
		//添加入result
		result.put("code", 0);
		result.put("data", jsonArray);
		result.put("count", total);
		ResponseUtil.write(response, result);
	}
	/** 
	 * 插入返回id
	 * @param param 实体条件
	 * @param response
	 * @throws Exception
	*/
	@RequestMapping("/insert")
	public void insert(PlanDetail param, HttpServletResponse response) throws Exception{
		Long id = PlanDetailService.insert(param);
		response.getWriter().print(id);
	}
	/** 
	 * 根据主键更新 返回影响行数
	 * @param param 实体条件
	 * @param response
	 * @throws Exception
	*/
	@RequestMapping("/update")
	public void update(PlanDetail param,HttpServletResponse response) throws Exception{
		Integer count = PlanDetailService.update(param);
		response.getWriter().print(count);
	}
	/** 
	 * 根据主键拼接的字符串删除返回影响行数
	 * @param ids 主键拼接的字符串
	 * @return 影响行数
	*/
	@RequestMapping("/delete")
	public void delete(String ids,HttpServletResponse response) throws Exception{
		ids=ids.replace("'",""); 
		Integer count = PlanDetailService.delete(ids);
		response.getWriter().print(count);
	}
}
